package com.chocho.javacompileserver.mapper;

import com.chocho.javacompileserver.bean.Paper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by chocho on 2022/5/20.
 */
@Mapper
@Repository
public interface PaperMapper {
    @Insert("INSERT INTO op_paper (paper_id, user_id, question_id, create_time, paper_score, paper_status, paper_answer, memory_limit, time_limit) " +
            "VALUES(#{paperId}, #{userId}, #{questionId}, #{createTime}, #{paperScore}, #{paperStatus}, #{paperAnswer}, #{memoryLimit}, #{timeLimit})")
    int insert(Paper paper);

    @Select("<script>" +
            "SELECT * FROM op_paper " +
            "<where>" +
            "<trim> " +
            "<if test=\"paperId != \'\' and paperId != null\"> paper_id like CONCAT('%',#{paperId},'%')</if> " +
            "</trim> " +
            "<trim prefix='and'> " +
            "<if test=\"userId != \'\' and userId != null\"> user_id like CONCAT('%',#{userId},'%')</if> " +
            "</trim> " +
            "<trim prefix='and'> " +
            "<if test=\"questionId != \'\' and questionId != null\"> question_id like CONCAT('%',#{questionId},'%')</if> " +
            "</trim> " +
            "<trim prefix='and'> " +
            "<if test=\"paperStatus != \'\' and paperStatus != null\"> paper_status like CONCAT('%',#{paperStatus},'%')</if> " +
            "</trim> " +
            "</where>" +
            "</script>")
    List<Paper> getPaperByQuery(Map<String, Object> map);
}
